package design.pattern.Lu06ProxyPattern;

/**
 * @program JavaBase
 * @description: 代理模式
 * @author: zhanglu
 * @create: 2020-03-29 10:01:00
 */
public class Lu06ProxyPattern {

    public static void main(String[] args) {

        IGamePlayer iGamePlayer = new GamePlayer("张三");

        GamePlayerProxy gamePlayerProxy = new GamePlayerProxy(iGamePlayer);

        gamePlayerProxy.login("zhangsan", "111111");
        gamePlayerProxy.killBoss();
        gamePlayerProxy.upgrade();

    }

}

interface IGamePlayer{

    void login(String username, String password);

    void killBoss();

    void upgrade();

}

class GamePlayer implements IGamePlayer{

    private String name;

    public GamePlayer(String name){
        this.name = name;
    }

    @Override
    public void login(String username, String password) {
        System.out.println("登陆：" + this.name + " - " + username + " - " + password);
    }

    @Override
    public void killBoss() {
        System.out.println("杀怪：" + this.name);
    }

    @Override
    public void upgrade() {
        System.out.println("升级：" + this.name);
    }

}

class GamePlayerProxy implements IGamePlayer{

    private IGamePlayer iGamePlayer;

    public GamePlayerProxy(IGamePlayer iGamePlayer){
        this.iGamePlayer = iGamePlayer;
    }

    @Override
    public void login(String username, String password) {
        this.iGamePlayer.login(username, password);
    }

    @Override
    public void killBoss() {
        this.iGamePlayer.killBoss();
    }

    @Override
    public void upgrade() {
        this.iGamePlayer.upgrade();
    }
}


